package com.doform.android.xianggucheng.model;

import com.doform.android.xianggucheng.model.impl.ILoginBiz;
import com.doform.android.xianggucheng.model.impl.OnLoginListener;
import com.doform.android.xianggucheng.utils.http.Api;
import com.doform.android.xianggucheng.utils.http.HttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/5/18.
 */

public class LoginBiz implements ILoginBiz {

    @Override
    public void login(final String phone, final String password, final OnLoginListener onLoginListener) {

        Map<String, String> maps = new HashMap<String, String>();
        maps.put("_v", "1.0");
        maps.put("_r", "android");
        maps.put("_n", "user");
        maps.put("_otype", "login");
        maps.put("_username", phone);
        maps.put("_password", password);
        HttpUtils.postRequest(Api.BASE_URL, maps, new StringCallback() {
            @Override
            public void onError(Call call, Exception e, int id) {
                onLoginListener.loginFailed();
            }

            @Override
            public void onResponse(String response, int id) {
                onLoginListener.loginSuccess(response);
            }
        });

    }

}
